package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.pojo.Goods;
import com.example.pojo.GsType;
import com.example.pojo.GsPy;
import com.example.pojo.GsPyDetail;
import com.example.mapper.GsPyDetailMapper;
import com.example.service.IGsPyDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 物品申请详细表 服务实现类
 * </p>
 *
 * @author wsl
 * @since 2022-04-11
 */
@Service
public class GsPyDetailServiceImpl extends ServiceImpl<GsPyDetailMapper, GsPyDetail> implements IGsPyDetailService {

    @Resource
    private GoodsServiceImpl goodsService;

    @Resource
    private GsTypeServiceImpl gsTypeService;

    public List<GsPyDetail> selectByPyId(List<GsPy> gsPy){
        QueryWrapper<GsPyDetail> queryWrapper1 = new QueryWrapper<>();
        List<Integer> list = new ArrayList<>();
        for (GsPy py : gsPy) {
            list.add(py.getId());
        }
        queryWrapper1.in("goods_py_id",list);

        List<GsPyDetail> gsPyDetails = list(queryWrapper1);

        for (GsPyDetail gsPyDetail : gsPyDetails) {
            Goods goods = goodsService.getById(gsPyDetail.getGsId());
            gsPyDetail.setGoods(goods);
            if (goods != null){
                GsType sss = gsTypeService.getById(goods.getGsTypeId());
                goods.setGsType(sss);
            }
            GsType gsType = gsTypeService.getById(gsPyDetail.getGoodsPyId());
            gsPyDetail.setGsType(gsType);
        }
        return null;
    }

}

